package com.cs.club.application.controller;

import com.cs.club.application.dtos.ClubInfoDTO;
import com.cs.club.common.entity.BaseResponse;
import com.cs.club.common.utlis.ResultUtils;
import com.cs.club.domain.bos.ClubInfoBO;
import com.cs.club.domain.service.ClubInfoDomainService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/club")
public class ClubInfoController {

    @Resource
    private ClubInfoDomainService clubInfoDomainService;

    @PostMapping("/add")
    public BaseResponse<Boolean> addClubInfo(@RequestBody ClubInfoDTO clubInfoDTO) {
        // 输出日志
        log.info("添加社团参数:{}", clubInfoDTO);
        // 类型转换
        ClubInfoBO clubInfoBO = new ClubInfoBO();
        BeanUtils.copyProperties(clubInfoDTO, clubInfoBO);
        // 调用domain层方法
        return ResultUtils.success(clubInfoDomainService.addClubInfo(clubInfoBO));
    }

    /**
     * 删除社团
     */
    @PostMapping("/delete")
    public BaseResponse<Boolean> deleteClubInfo(@RequestBody ClubInfoDTO clubInfoDTO) {
        // 输出日志
        log.info("删除社团参数:{}", clubInfoDTO);
        // 类型转换
        ClubInfoBO clubInfoBO = new ClubInfoBO();
        BeanUtils.copyProperties(clubInfoDTO, clubInfoBO);
        // 调用domain层方法
        return ResultUtils.success(clubInfoDomainService.deleteClubInfo(clubInfoBO));
    }

    @PostMapping("/update")
    public BaseResponse<Boolean> updateClubInfo(@RequestBody ClubInfoDTO clubInfoDTO) {
        // 输出日志
        log.info("修改社团参数:{}", clubInfoDTO);
        // 类型转换
        ClubInfoBO clubInfoBO = new ClubInfoBO();
        BeanUtils.copyProperties(clubInfoDTO, clubInfoBO);
        // 调用domain层方法
        return ResultUtils.success(clubInfoDomainService.updateClubInfo(clubInfoBO));
    }
}
